﻿@page
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>用户登陆 - 升级管理系统</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="~/css/layui.css" media="all" />
    <link rel="stylesheet" href="~/css/login.css" media="all" />
</head>
<body>
    <div class="layui-container">
        <div id="wrapper" class="login-page">
            <div id="login_form" class="form">
                <form class="register-form layui-form">
                    <input type="text" name="User" placeholder="用户名" lay-verify="username" />
                    <input type="password" name="Pass" placeholder="密码" lay-verify="password" />
                    <input type="text" name="Nick" placeholder="昵称" lay-verify="required" />
                    <button lay-submit lay-filter="regedit">创建账户</button>
                    <p class="message">已经有了一个账户? <a href="#">立刻登录</a></p>
                </form>
                <form class="login-form layui-form">
                    <input type="text" name="User" placeholder="用户名" lay-verify="username" />
                    <input type="password" name="Pass" placeholder="密码" lay-verify="password" />
                    <button lay-submit lay-filter="login">登　录</button>
                    <p class="message">还没有账户? <a href="#">立刻创建</a></p>
                </form>
            </div>
        </div>
    </div>

    <script src="~/layui.js"></script>
    <script>
        layui.use(['form'], function () {
            var $ = layui.jquery
                , form = layui.form;

            form.verify({
                username: function (value, item) {
                    if (value === "") {
                        return '用户名不能为空';
                    }
                    if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                        return '用户名不能有特殊字符';
                    }
                    if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                        return '用户名首尾不能出现下划线\'_\'';
                    }
                    if (value.length < 6 | value.length > 12) {
                        return '用户名必须6到12位，且不能出现空格';
                    }
                }
                , password: function (value, item) {
                    if (value === '') {
                        return '密码不能为空';
                    }
                    if (!new RegExp("/^[\S]{6,12}$/")) {
                        return '密码必须6到12位，且不能出现空格';
                    }

                }
            });

            form.on('submit(login)', function (data) {
                $.ajax({
                    url: '/Api/User/Login'
                    , type: 'POST'
                    , contentType: 'application/json'
                    , data: JSON.stringify(data.field)
                    , success: function (res) {
                        if (res.ok === false) {
                            $("#login_form").removeClass('shake_effect');
                            setTimeout(function () {
                                $("#login_form").addClass('shake_effect')
                            }, 1);
                            layer.msg(res.mess, { icon: 5 });
                        } else {
                            window.location.href = "/Product";
                        }
                    }
                });

                return false;
            });
            form.on('submit(regedit)', function (data) {
                $.ajax({
                    url: '/Api/User/Regedit'
                    , type: 'POST'
                    , contentType: 'application/json'
                    , data: JSON.stringify(data.field)
                    , success: function (res) {
                        if (res.ok === false) {
                            $("#login_form").removeClass('shake_effect');
                            setTimeout(function () {
                                $("#login_form").addClass('shake_effect')
                            }, 1);
                            layer.msg(res.mess, { icon: 5 });
                        } else {
                            window.location.href = "/Product";
                        }
                    }
                });

                return false;
            });
            

            $('.message a').click(function () {
                $('form').animate({
                    height: 'toggle',
                    opacity: 'toggle'
                }, 'slow');
            });
        });
    </script>
</body>
</html>
